﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using CompanyBussiness;

namespace Website.admin.Control
{
    public partial class UploadFileAttach : System.Web.UI.UserControl
    {
        string strFileName = "";
        string typeFile;

        protected void Page_Load(object sender, EventArgs e)
        {
            Upload();
        }

        protected void Upload()
        {
            HttpPostedFile hpfFile = Request.Files["myfile"];
            String path = Server.MapPath(ConfigurationManager.AppSettings["FolderFileUpload"]);

            if (Path.GetExtension(hpfFile.FileName.ToLower()) == ".doc" || Path.GetExtension(hpfFile.FileName.ToLower()) == ".docx" || Path.GetExtension(hpfFile.FileName.ToLower()) == ".pdf" || Path.GetExtension(hpfFile.FileName.ToLower()) == ".txt" || Path.GetExtension(hpfFile.FileName.ToLower()) == ".xls" || Path.GetExtension(hpfFile.FileName.ToLower()) == ".xlsx")
            {

                try
                {
                    int index = hpfFile.FileName.LastIndexOf('.');
                    typeFile = hpfFile.FileName.Substring(index);
                    strFileName = Path.GetFileName(hpfFile.FileName);

                    Session[CONST.SESSION_FILE_ATTACH] = strFileName;
                    hpfFile.SaveAs(path + strFileName);
                    
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                }
            }
            
        }
    }
}